$(function(){
	//表单验证所需要
	$('#commentForm').validate({
				rules:{
					curl:'required',
					cname:{
						'required':true
					},
					pas1:{
						
					},
					pas2:{
						equalTo:"#field"
					}
					
				},
				messages:{
					cname:{
						required:"您必须输入点什么",
					}
				}
			});
		
	//输入信息注册
	$('.register .content .bottom #submit').on('click',function(){
		console.log('13');		
		var name = $('.register input').eq(0).val();
		var password1 = $('.register input').eq(1).val();
		var  password2= $('.register input').eq(2).val();
		var email = $('.register input').eq(3).val();
		var qq = $('.register input').eq(4).val();
		console.log(qq);
		//Ajax上传数据
		var param ={};
		param.name = name;
		param.password1=password1;
		param.password2=password2;
		param.email=email;
		param.qq=qq;
		if($('#commentForm').valid()){
			
			$.post('register.php',param,function(data){
					console.log(data);
			 		if(data.code == 1){
			 			alert('注册成功');
						console.log('插入成功了');
			             // 注册成功之后跳转到登录页面,不能加这句话!!!
			 			// location.href = "../zzw/dl.html"; 
			 			
			 		}else{
			 			alert('注册失败');
			 		}
				},'json');
//			alert('插入成功');
			//跳转到首页
//			location.href = "../zzw/dl.html";
		}else{
			console.log('验证不对');
			$('.register .content .bottom .p2 .sp1').html('请输入正确的格式')
		}
		
	})
	
	// ajax异步提交表单
	$('.pn').click(function(){
		var username = $('#username').val();
		var password = $('#password').val();
		var param = {};
		param.username=username;
		param.password = password;
		// console.log(param);
		$.post('public/public_login.php',param,function(data){						
			if (data.code == 1) {
				alert('登录成功');				
				$('.wei_login').slideUp(500);
			}else{
				alert('登录失败');
				$('.wei_login').css('display','block');
				$('#username').val('');
				$('#password').val('');
			}
		},'json');
	}) 
	
	
	
	
	
	
	
	
})
